﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class SystemManager_EmailSendedList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetGVData("");        
        }
    }

    void GetGVData(string filterStr)
    {
        GoShopping.BLL.SysInfo.Log_EmailSendListBean log_EmailBean = new GoShopping.BLL.SysInfo.Log_EmailSendListBean();
        gvMailList.DataSource=log_EmailBean.GetLogMail(filterStr);
        gvMailList.DataBind();
    }

    protected void lblSendMail_Click(object sender, EventArgs e)
    {
        // 使用ArrayList记录选择的项
        ArrayList selList = new ArrayList();
        int i = 0;
        // 遍历数据集
        foreach (GridViewRow row in this.gvMailList.Rows)
        {
            // 获取行首的CheckBox，判断是否为Checked
            CheckBox cb = (CheckBox)row.FindControl("cbSingle");
            if (cb.Checked == false)
            {
                continue;
            }
            //// 若为Checked,将信息添加到ArrayList
            selList.Add(Convert.ToInt16(((Label)row.FindControl("lblID")).Text));
            i++;
        }
        // 若遍历完成后ArrayList为空，则表示未选中任何项，页面提示
        if (selList.Count == 0)
        {
            return;
        }
        // 调用逻辑方法,发送邮件
        GoShopping.BLL.SysInfo.Log_EmailSendListBean log_EmailBean = new GoShopping.BLL.SysInfo.Log_EmailSendListBean();
        GoShopping.Utility.MailUtility mu = new GoShopping.Utility.MailUtility();
        for (int j = 0; j < selList.Count; j++)
        {
            try
            {
                //mu.SetMail()
                //log_EmailBean.UpdateOneLogMailSendStatue(Convert.ToInt16(selList[j]));
            }
            catch
            {
                //log_EmailBean.UpdateOneLogMailSendStatue(Convert.ToInt16(selList[j]));
            }

        }
        // 重新绑定
        GetGVData("");
    }
    protected void cbAll_CheckedChanged(object sender, EventArgs e)
    {
        // 遍历数据集的所有数据项
        foreach (GridViewRow row in this.gvMailList.Rows)
        {
            // 取得数据项行首的CheckBox，使其Checked属性与表头的CheckBox同步
            CheckBox subCB = (CheckBox)row.FindControl("cbSingle");
            subCB.Checked = ((CheckBox)sender).Checked;
        }
    }
    protected void gvMailList_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvMailList.PageIndex = e.NewPageIndex;
        GetGVData("");
    }
}
